package com.darkplanet.management.controller;

import com.darkplanet.management.domain.Employee;
import com.darkplanet.management.service.EmployeeServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/UserLookServlet")
public class UserLookServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer employee_id = Integer.parseInt(request.getParameter("employee_id"));
        String url_to = request.getParameter("url_to");
        EmployeeServiceImp employeeService = new EmployeeServiceImp();
        Employee employee = employeeService.getEmployeeBYId(employee_id);
        request.getSession().setAttribute("user", employee);
        if (url_to.equals("0")) {
            request.getSession().setAttribute("employee_id",employee_id);
            response.sendRedirect(request.getContextPath() + "/user-edit.jsp");
        }else if(url_to.equals("1")){
            response.sendRedirect(request.getContextPath() + "/user-look.jsp");
        }
    }
}
